// Copyright (c) Microsoft Corporation and Contributors.
// Licensed under the MIT License.

using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using WhaleAccount.Contracts.Services;
using WhaleAccount.ViewModels;
using Type = WhaleAccount.Models.Type;

namespace WhaleAccount.Views;
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class TypesPage : Page
{
    private readonly ITypeService _typeService;
    public TypesViewModel ViewModel
    {
        get;
    }
    public TypesPage()
    {
        _typeService = App.GetService<ITypeService>();

        ViewModel = App.GetService<TypesViewModel>();
        InitializeComponent();
    }

    private void VisibleToggleSwitch_Toggled(object sender, RoutedEventArgs e)
    {
        var toggleSwitch = sender as ToggleSwitch;
        if (toggleSwitch != null && toggleSwitch.DataContext != null)
        {
            if (toggleSwitch.DataContext is Type type)
            {
                type.Visible = toggleSwitch.IsOn;
                _typeService.UpdateTypeAsync(type);
            }
        }
    }

}
